home *** CD-ROM | disk | FTP | other *** search
- {$M 16384,0,0}
-
- {**************************************************************************}
- {* *}
- {* CityFix; Capitalizes the City field in QuickBBS's USERS.BBS so *}
- {* it won't look so ugly! Written for QuickBBS 2.04 - 2.63 *}
- {* Questions/Comments contact Chris Lamprecht at 1:382/36 FidoNet *}
- {* Compiled with Borland's Turbo Pascal Compiler version 5.5 *}
- {* *}
- {**************************************************************************}
-
- {/* NOTE: Since I get the LAST word from City/State field, two word
- Cities (South Dakota, etc) cannot be checked correctly! That is why
- the source is here. I have assumed anything ending with "York" is New
- York, but... Have fun */}
-
- Program CityFix;
-
- Uses Dos, Crt;
-
- Const
- Version = 'v1.01';
- UserFile = 'USERS.BBS';
-
- Type
- CityStr = String[25];
-
- {$I STRUCT.263}
-
- Var
- X, Loop, G : Integer;
- F, T : File of UserRecord;
- Exp, Compr,
- StripPeriod,
- KillBack : Boolean;
- State : Array[1..65] of String[3];
-
-
- Function FileExist(FileName:String):Boolean;
- Var f : file;
- Begin
- {$I-}
- Assign(f,filename);
- Reset(f);
- Close(f);
- {$I+}
- FileExist := (IOResult = 0) and (FileName <> '');
- End;
-
- Function Strip(TCity:CityStr):CityStr; { Strips periods }
- Begin
- Repeat
- If Pos('.',TCity) <> 0 then Delete(TCity,Pos('.',TCity),1);
- Until Pos('.',TCity) = 0;
- Strip := TCity;
- End;
-
- Function Lower(Str:string):string; { Makes Str all lowercase }
- var
- I : integer;
- begin
- For I := 1 to length(Str) do
- If ord(Str[I]) in [65..90] then
- Str[I] := chr(ord(Str[I]) + 32);
- Lower := Str;
- End; {Func Lower}
-
- Function Proper(Str:string):string; { caps the first letter of words }
- var
- I : integer;
- SpaceBefore: boolean;
- begin
- SpaceBefore := true;
- Str := lower(Str);
- For I := 1 to length(Str) do
- {If SpaceBefore and (ord(Str[I]) in [97..122]) then}
- If SpaceBefore and (ord(Str[I]) in [97..173]) then
- begin
- SpaceBefore := False;
- Str[I] := Upcase(Str[I]);
- end
- else
- If (SpaceBefore = False) and (Str[I] = ' ') then
- SpaceBefore := true;
- Proper := Str;
- end;
-
- Function Cap(TCity:CityStr):CityStr; { fixes some spacing }
- Begin
- For x := 1 to length(TCity)-1 do
- Begin
- If TCity[x] = ' ' then
- If TCity[x+1] = ',' then
- Delete(TCity,x,1);
- End;
- For X := 1 to Length(TCity)-1 do
- Begin
- If TCity[x] = ',' then
- if TCity[x+1] <> ' ' then Insert(' ',TCity,x+1);
- End;
- { Repeat
- If (Pos(',',TCity) = 0) and (Pos(' ',TCity) > 0) then
- Insert(',',TCity, Pos(' ',TCity));
- Until Pos(',',TCity) <> 0; }
- Cap := Proper(TCity);
- End;
-
- Function Last(N:byte;Str:string):string; { Gets last word in City,St }
- var Temp : string;
- begin
- If N > length(Str) then
- Temp := Str
- else
- Temp := copy(Str,succ(length(Str) - N),N);
- Last := Temp;
- end; {Func Last}
-
- Function LastPos(C:Char;Str:string):byte; { Finds last position of char }
- Var I : byte;
- begin
- I := succ(Length(Str));
- Repeat
- I := Pred(I);
- Until (I = 0) or (Str[I] = C);
- LastPos := I;
- end; {Func LastPos}
-
- Function Expand(TCity:CityStr):CityStr; { expands abbr. to state }
- Var
- City,
- State : String[25];
-
- Begin
- City := Copy(TCity,1,LastPos(' ',TCity));
- State := Copy(TCity,Succ(LastPos(' ',TCity)),length(TCity));
- If State = 'Al' then State := 'Alabama';
- If State = 'Ak' then State := 'Alaska';
- If State = 'Az' then State := 'Arizona';
- If State = 'Ar' then State := 'Arkansas';
- If State = 'Ca' then State := 'California';
- If State = 'Co' then State := 'Colorado';
- If State = 'Ct' then State := 'Connecticut';
- If State = 'De' then State := 'Delaware';
- If State = 'Dc' then State := 'District of Columbia';
- If State = 'Fl' then State := 'Florida';
- If State = 'Ga' then State := 'Georgia';
- If State = 'Gu' then State := 'Guam'; { Guam!?? }
- If State = 'Hi' then State := 'Hawaii';
- If State = 'Id' then State := 'Idaho';
- If State = 'Il' then State := 'Illinois';
- If State = 'In' then State := 'Indiana';
- If State = 'Ia' then State := 'Iowa';
- If State = 'Ks' then State := 'Kansas';
- If State = 'Ky' then State := 'Kentucky';
- If State = 'La' then State := 'Louisiana';
- If State = 'Me' then State := 'Maine';
- If State = 'Md' then State := 'Maryland';
- If State = 'Ma' then State := 'Massachusetts';
- If State = 'Mi' then State := 'Michigan';
- If State = 'Mn' then State := 'Minnesota';
- If State = 'Ms' then State := 'Mississippi';
- If State = 'Mo' then State := 'Missouri';
- If State = 'Mt' then State := 'Montana';
- If State = 'Ne' then State := 'Nebraska';
- If State = 'Nv' then State := 'Nevada';
- If State = 'Nh' then State := 'New Hampshire';
- If State = 'Nj' then State := 'New Jersey';
- If State = 'Nm' then State := 'New Mexico';
- If State = 'Ny' then State := 'New York';
- If State = 'Nc' then State := 'North Carolina';
- If State = 'Nd' then State := 'North Dakota';
- If State = 'Oh' then State := 'Ohio';
- If State = 'Ok' then State := 'Oklahoma';
- If State = 'Or' then State := 'Oregon';
- If State = 'Pa' then State := 'Pennsylvania';
- If State = 'Pr' then State := 'Puerto Rico';
- If State = 'Ri' then State := 'Rhode Island';
- If State = 'Sc' then State := 'South Carolina';
- If State = 'Sd' then State := 'South Dakota';
- If State = 'Tn' then State := 'Tennessee';
- If State = 'Tx' then State := 'Texas';
- If State = 'Ut' then State := 'Utah';
- If State = 'Vt' then State := 'Vermont';
- If State = 'Va' then State := 'Virginia';
- If State = 'Wa' then State := 'Washington';
- If State = 'Wv' then State := 'West Virginia';
- If State = 'Wi' then State := 'Wisconsin';
- If State = 'Wy' then State := 'Wyoming';
- If State = 'Bc' then State := 'British Columbia';
- If State = 'Mb' then State := 'Manitoba';
- If State = 'Nb' then State := 'New Brunswick';
- If State = 'Nf' then State := 'Newfoundland';
- If State = 'Ns' then State := 'Nova Scotia';
- If State = 'On' then State := 'Ontario';
- If State = 'Pe' then State := 'Prince Edward Island';
- If State = 'Pq' then State := 'Quebec';
- If State = 'Sk' then State := 'Saskatchewan';
- If State = 'Yk' then State := 'Yukon';
- If State = 'Nw' then State := 'Northwest Territories';
- Expand := City + State;
- End;
-
- Function Compress(TCity:CityStr):CityStr; { compress state to abbrev. }
- Var
- City,
- State : String[25];
-
- Begin
- City := Copy(TCity,1,LastPos(' ',TCity));
- State := Copy(TCity,Succ(LastPos(' ',TCity)),Length(TCity));
- If State = 'Alabama' then State := 'AL';
- If State = 'Alaska' then State := 'AK';
- If State = 'Arizona' then State := 'AZ';
- If State = 'Arkansas' then State := 'AR';
- If State = 'California' then State := 'CA';
- If State = 'Colorado' then State := 'CO';
- If State = 'Connecticut' then State := 'CT';
- If State = 'Delaware' then State := 'DE';
- If State = 'District of Columbia' then State := 'DC'; {*}
- If State = 'Florida' then State := 'FL';
- If State = 'Georgia' then State := 'GA';
- If State = 'Guam' then State := 'GU';
- If State = 'Hawaii' then State := 'HI';
- If State = 'Idaho' then State := 'ID';
- If State = 'Illinois' then State := 'IL';
- If State = 'Indiana' then State := 'IA';
- If State = 'Iowa' then State := 'IO';
- If State = 'Kansas' then State := 'KS';
- If State = 'Kentucky' then State := 'KY';
- If State = 'Louisiana' then State := 'LA';
- If State = 'Maine' then State := 'ME';
- If State = 'Maryland' then State := 'MD';
- If State = 'Massachusetts' then State := 'MA';
- If State = 'Michigan' then State := 'MI';
- If State = 'Minnesota' then State := 'MN';
- If State = 'Mississippi' then State := 'MS';
- If State = 'Missouri' then State := 'MO';
- If State = 'Montana' then State := 'MT';
- If State = 'Nebraska' then State := 'NE';
- If State = 'Nevada' then State := 'NV';
- If State = 'Hampshire' then State := 'NH';
- If State = 'Jersey' then State := 'NJ';
- If State = 'Mexico' then State := 'NM';
- If State = 'New York' then State := 'NY'; {*}
- If State = 'Morth Carolina' then State := 'NC'; {*}
- If State = 'North Dakota' then State := 'ND'; {*}
- If State = 'Ohio' then State := 'OH';
- If State = 'Oklahoma' then State := 'OK';
- If State = 'Oregon' then State := 'OR';
- If State = 'Pennsylvania' then State := 'PA';
- If State = 'Puerto Rico' then State := 'PR'; {*}
- If State = 'Rhode Island' then State := 'RI'; {*}
- If State = 'South Carolina' then State := 'SC'; {*}
- If State = 'South Dakota' then State := 'SD'; {*}
- If State = 'Tennessee' then State := 'TN';
- If State = 'Texas' then State := 'TX';
- If State = 'Utah' then State := 'UT';
- If State = 'Vermont' then State := 'VT';
- If State = 'Virginia' then State := 'VA';
- If State = 'Washington' then State := 'WA';
- If State = 'West Virginia' then State := 'WV'; {*}
- If State = 'Wisconsin' then State := 'WI';
- If State = 'Wyoming' then State := 'WY';
- If State = 'Alberta' then State := 'AB';
- If State = 'Columbia' then State := 'BC';
- If State = 'Manitoba' then State := 'MB';
- If State = 'Brunswick' then State := 'NB';
- If State = 'Newfoundland' then State := 'NF';
- If State = 'Scotia' then State := 'NS';
- If State = 'Ontario' then State := 'ON';
- If State = 'Prince Edward Island' then State := 'PE'; {*}
- If (State = 'Quebec') or (State = 'Québec') then State := 'PQ';
- If State = 'Saskatchewan' then State := 'SK';
- If State = 'Yukon' then State := 'YK';
- If State = 'Territories' then State := 'NW';
- Compress := City + State;
- End;
-
- {*} { = Two word state - I was too lazy to think on this one. }
-
-
- Procedure Backup; { Backs up users.bbs with 4K buffer }
- Var
- FromF, ToF : File;
- NRead,
- NWritten : Word;
- Buf : Array[1..4096] of Char;
-
- Begin
- TextColor(2);
- Writeln('Writing backup file ''USERS.BAK''',#13,#10);
- Assign(FromF, UserFile);
- Reset(FromF, 1);
- Assign(ToF, 'USERS.BAK');
- Rewrite(ToF, 1);
- Repeat
- BlockRead(FromF, buf, SizeOf(buf), NRead);
- BlockWrite(ToF, buf, NRead, NWritten);
- Until (NRead = 0) or (NWritten <> NRead);
- Close(FromF);
- Close(ToF);
- End;
-
- Procedure HelpScreen; { of all things; the helpscreen }
- Begin
- TextColor(2);
- Writeln('USAGE:'#13,#10);
- TextColor(10);
- Writeln(' CityFix [-B] [-E or -C] [-P]',#13,#10);
- TextColor(2);
- Writeln('-B = Do not erase backup file USERS.BAK');
- Writeln('-C = Compress States/Provinces into Abbreviations');
- Writeln('-E = Expand State/Province Abbreviations');
- Writeln('-P = Strip ALL periods from City/States',#13,#10);
- Writeln('This must be run in the same directory as the USERS.BBS file.');
- TextColor(7);
- Writeln('Exit Code = 1');
- Halt(1);
- End;
-
- Procedure Init; { what else! }
- Begin
- ClrScr;
- TextColor(3);
- Writeln('CityFix '+Version+' by Chris Lamprecht of FidoNet 1:382/36',#13,#10);
- TextColor(7);
- G := 0;
- If not FileExist('USERS.BBS') then
- Begin
- TextColor(12);
- Writeln('Users.BBS not found in current directory!');
- HelpScreen;
- End;
- Exp := FALSE;
- Compr := FALSE;
- KillBack := TRUE;
- StripPeriod := FALSE;
- For X := 1 to ParamCount do
- Begin
- If (ParamStr(X) = '/?') or (ParamStr(X) = '?') then HelpScreen;
- If (ParamStr(X) = '-E') or (ParamStr(X) = '-e') then Exp := TRUE;
- If (ParamStr(X) = '-C') or (ParamStr(X) = '-c') then Compr := TRUE;
- If (ParamStr(X) = '-B') or (ParamStr(X) = '-b') then KillBack := FALSE;
- If (ParamStr(X) = '-P') or (ParamStr(X) = '-p') then StripPeriod := TRUE;
- If (Compr = TRUE) and (Exp = TRUE) then
- Begin
- Compr := FALSE;
- Exp := FALSE;
- Writeln('You can''t compress States AND Expand states!');
- End;
- End;
- End;
-
- Procedure Do_It; { guts of cityfix }
- Var Tuse : UserRecord;
- OldCity : String[25];
-
- Begin
- Assign(f,UserFile);
- Reset(f);
- If StripPeriod then
- Begin
- Write('Stripping Periods');
- If Exp or Compr then Write(', ') else Write(' and ');
- End;
- If Exp then Write('Expanding and ');
- If Compr then Write('Compressing and ');
- Writeln('Capitalizing ',FileSize(f),' Users'' Cities/States ...'#13,#10);
- For Loop := 0 to FileSize(f)-1 do
- Begin
- Seek(f,loop);
- Read(f,Tuse);
- OldCity := Tuse.City;
- Tuse.City := Cap(Tuse.City);
- If StripPeriod then Tuse.City := Strip(Tuse.City);
- If Compr then Tuse.City := Compress(Tuse.City);
- If Exp then Tuse.City := Expand(Tuse.City);
- Write(Loop+1:4,' ',OldCity:25,' -> ',Tuse.City,' ',#13);
- If OldCity <> Tuse.City then G := G + 1;
- Seek(F,loop);
- Write(f,Tuse);
- End;
- Close(f);
- Writeln(#13,#10);
-
- If KillBack then
- Begin
- Writeln('Deleting backup file ''USERS.BAK'''#13,#10);
- Assign(t,'USERS.BAK');
- Erase(t);
- End;
- TextColor(7);
- Write(G,' UserRecords were changed.');
- Halt(0);
- End;
-
- Begin
- CheckSnow := TRUE;
- Init;
- Backup;
- Do_it;
- End.